# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: handle_map_util.py
  @time: 2022/11/14 10:16
  @desc:
"""
import random
from pathlib import Path
from configparser import ConfigParser

map_path = r"C:\Users\Jingw\Desktop\test.map"


def handle_map(map_path):
    config = ConfigParser()
    config.read(map_path)
    sections_list = config.sections()
    for section in sections_list:
        if "Die" == section:
            for key, value in config.items(section):
                if "P" in value:
                    value = value.replace("P", "1")
                    valid_list = list(value)
                    valid_list.insert(0,f"{str(random.randint(0,100))},")
                    value = "".join(valid_list)
                    print(f'{key}={value.replace(",,", ",ToBeProbed,0")}')
                else:
                    value = value.replace("X", "-1")
                    invalid_list = list(value)
                    invalid_list.insert(0, "-1,")
                    value = "".join(invalid_list)
                    print(f'{key}={value.replace(",,", ",Removed,0")}')


handle_map(map_path)
